﻿using System;
namespace StatisticsCalculator
{
    public class Statistics
    {
        double[] sampleData;
        double size;
        public Statistics(double[] sampleData)
        {
            size = sampleData.Length;
            if (size < 1)
                throw new ArgumentException("Invalid size of sample Data");
            this.sampleData = sampleData;
          

        }
        public double[] SampleData
        {
            get { return sampleData; }

            set
            {
                sampleData = value;
            }
        }

        public double calculateExpectedValueForUniformDistribution()
        {
            double expectedValue = 0.0;
            for (int i = 0; i < size; i++)
            {
                expectedValue += sampleData[i];
            }
            expectedValue /= size;

            return expectedValue;
        }

        public double calculateVarianceForUniformDistribution()
        {

            double variance = 0.0;
            for (int i = 0; i < size; i++)
            {
                variance += Math.Pow(sampleData[i], 2);
            }
            variance /= size;
            variance -= Math.Pow(calculateExpectedValueForUniformDistribution(), 2);

            return variance;
        }

        public double calculateMean()
        {
            double sum = 0.0;
            foreach (double a in sampleData)
                sum += a;
            return sum / size;
        }
        public double calculateVariance()
        {
            double mean = calculateMean();
            double temp = 0;
            foreach (double a in sampleData)
                temp += (mean - a) * (mean - a);
            return temp / size;
        }


        public double calculateSkewness()
        {
            double mean = calculateMean();
            double numerator = 0, denominator = 0;

            for (int i = 0; i < size; i++)
            {
                numerator += Math.Pow(sampleData[i] - mean, 3);
                denominator += Math.Pow(sampleData[i] - mean, 2);
            }

            numerator = (1.0 / size) * numerator;

            denominator = Math.Pow(denominator * (1.0 / size), 3.0 / 2.0);
            return numerator / denominator;
        }


        public double calculateKurtosis()
        {
            double mean = calculateMean();
            double numerator = 0, denominator = 0;

            for (int i = 0; i < size; i++)
            {
                numerator += Math.Pow(sampleData[i] - mean, 4);
                denominator += Math.Pow(sampleData[i] - mean, 2);
            }

            numerator = (double)(1.0 / sampleData.Length) * numerator;

            denominator = Math.Pow(denominator * (double)(1.0 / sampleData.Length), 2);

            return (numerator / denominator) - 3;
        }

    }
}
      